/*
 * Copyright (C) 2008 Rob Cash
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * 	http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * SubscriptionModel.java
 */

package org.robcash.apps.messagepopup.view.wizard;

import org.robcash.apps.messagepopup.vo.MessageStore;
import org.robcash.apps.messagepopup.vo.Schedule;
import org.robcash.apps.messagepopup.vo.SubscriptionStore;
import org.robcash.commons.swing.wizard.WizardPanel;
import org.robcash.commons.swing.wizard.model.DefaultWizardModel;

/**
 * Model for maintaining information used to create or edit a subscription
 * @author Rob
 */
public class SubscriptionModel extends DefaultWizardModel {

    public final static String SUBSCRIPTION_CHOOSER = "subscriptionChooser";
    public final static String LOCAL_FILE = "localFile";
    public final static String REMOTE_FILE = "remoteFile";
    public final static String VALIDATOR = "validator";
    public final static String SCHEDULE_CHOOSER = "scheduleChooser";
    public final static String SCHEDULE_EDITOR = "scheduleEditor";
    public static final String SCHEDULE_NAME = "scheduleName";

    private SubscriptionStore subscriptionStore;
    private String subscriptionName;
    private MessageStore messageStore;
    private Schedule schedule;
    private boolean scheduleIsNew = false;
    
    public SubscriptionModel() {
        super();
        
        // Add panels
        WizardPanel typePanel = new SubscriptionTypeWizardPanel(SUBSCRIPTION_CHOOSER);
        WizardPanel localFilePanel = new LocalFileChooserWizardPanel(LOCAL_FILE);
        WizardPanel remoteFilePanel = new RemoteFileLocationWizardPanel(REMOTE_FILE);
        WizardPanel validationPanel = new MessageSourceValidationPanel(VALIDATOR);
        WizardPanel scheduleChooserPanel = new ScheduleChooserWizardPanel(SCHEDULE_CHOOSER);
        WizardPanel scheduleEditorPanel = new ScheduleEditorWizardPanel(SCHEDULE_EDITOR);
        WizardPanel scheduleNamePanel = new ScheduleNameWizardPanel(SCHEDULE_NAME);
        add(typePanel, true);
        add(localFilePanel);
        add(remoteFilePanel);
        add(validationPanel);
        add(scheduleChooserPanel);
        add(scheduleEditorPanel);
        add(scheduleNamePanel);

        // Add transitions
        add(typePanel, localFilePanel, LOCAL_FILE);
        add(typePanel, remoteFilePanel, REMOTE_FILE);
        add(localFilePanel, validationPanel, NEXT);
        add(remoteFilePanel, validationPanel, NEXT);
        add(validationPanel, scheduleChooserPanel, NEXT);
        add(scheduleChooserPanel, scheduleEditorPanel, SCHEDULE_EDITOR);
        add(scheduleChooserPanel, scheduleNamePanel, SCHEDULE_NAME);
        add(scheduleEditorPanel, scheduleNamePanel, NEXT);
    }

    /**
     * Get the subscription store
     * @return Subscription store
     */
    public SubscriptionStore getSubscriptionStore() {
        return subscriptionStore;
    }

    /**
     * Set the subscription store
     * @param store Subscription store
     */
    public void setSubscriptionStore(SubscriptionStore store) {
        this.subscriptionStore = store;
    }

    /**
     * Get the message store
     * @return message store
     */
    public MessageStore getMessageStore() {
        return this.messageStore;
    }
    
    /**
     * Set the message store
     * @param store Message store
     */
    public void setMessageStore(MessageStore store) {
        this.messageStore = store;
    }

    /**
     * Get the subscription
     * @return Subscription
     */
    public String getSubscriptionName() {
        return subscriptionName;
    }

    /**
     * Set the subscription
     * @param subscriptionName Subscription to add
     */
    public void setSubscriptionName(String subscriptionName) {
        this.subscriptionName = subscriptionName;
    }
    
    /**
     * Get the schedule
     * @return Schedule
     */
    public Schedule getSchedule() {
        return schedule;
    }

    /**
     * Set the schedule
     * @param schedule Schedule
     */
    public void setSchedule(Schedule schedule) {
        this.schedule = schedule;
    }

    /**
     * Set the schedule is new indicator
     * @param newSchedule Indicates if the schedule is new (true) or edited
     */
    public void setScheduleIsNew(boolean newSchedule) {
        this.scheduleIsNew = newSchedule;
    }

    /**
     * Indicates if the schedule is new
     * @return true if the schedule is new; false if it is edited
     */
    public boolean isScheduleNew() {
        return scheduleIsNew;
    }

}
